# -*- coding: utf-8 -*- 

"""
PeerTool application master configuration file. 

Make your changes in a copy of this file. Name the copy 0config.py. The leading
'0' ensures that your version will be processed before any other model files.
You may delete the original version (1config.py) if you wish or leave it in
place. The try/except at the top of the file will keep it from being executed
since your version will have run first.  

See the web2py book online for explanation of the various web2py-specific
variables.  Variables specific to PeerTool are at the bottom of the file.

This file is part of PeerTool, a web application for collaborative
decision-making (Copyrighted, 2009-2010, Ellis & Grant, Inc.)
Developed by Michael F. Ellis <michael.f.ellis@gmail.com>.  
License: AGPL v3
PeerTool comes with ABSOLUTELY NO WARRANTY.
"""                
try:
    PTCFG=PTCFG                                 # Already configured if PTCFG 
                                                # exists
except NameError:

    #--------------------------------------------------------
    # Web2py application configuration
    #--------------------------------------------------------
    applogger = local_import('applogger')
    debug = applogger.consoleLogger(request.application).debug
    warn = applogger.consoleLogger(request.application).warn
    #########################################################################
    ## This scaffolding model makes your app work on Google App Engine too
    #########################################################################

    if request.env.web2py_runtime_gae:          # if on Google App Engine
        db = DAL('gae')                         # connect to Google BigTable
        session.connect(request, response, db=db) # and store sessions and 
                                                # tickets there
        ### or use the following lines to store sessions in Memcache
        # from gluon.contrib.memdb import MEMDB
        # from google.appengine.api.memcache import Client
        # session.connect(request, response, db=MEMDB(Client())
    else:                                       # else use a normal 
                                                # relational database.
        db = DAL('sqlite://storage.sqlite')     # Specify database here

    ## if no need for session
    # session.forget()

    #########################################################################
    ## Here is sample code if you need for 
    ## - email capabilities
    ## - authentication (registration, login, logout, ... )
    ## - authorization (role based authorization)
    ## - services (xml, csv, json, xmlrpc, jsonrpc, amf, rss)
    ## - crud actions
    ## comment/uncomment as needed

    from gluon.tools import *
    auth=Auth(globals(),db)                     # authentication/authorization
    auth.settings.hmac_key = \
        'sha512:your-super-secret-passphrase'   # see web2py book, ch. 8
    auth.define_tables()                        # creates all needed tables
    crud=Crud(globals(),db)                     # for CRUD helpers using auth
    service=Service(globals())                  # for json, xml, jsonrpc, 
                                                # xmlrpc, amfrpc

    #crud.settings.auth=auth                    # enforces authorization on crud

    mail=Mail()                                 # mailer
    if request.env.web2py_runtime_gae:          # if running on Google App Engine
        debug("setting mail.server to 'gae'")
        mail.settings.server='gae'              # standard setting
    else:
        mail.settings.server='smtp.gmail.com:587'      # your SMTP server

    mail.settings.sender='peertool.noreply@gmail.com'  # your email
    mail.settings.login='peertool.noreply:notmypasswd' # your credentials or None
    auth.settings.mailer=mail                          # for user email verification

    auth.settings.registration_requires_verification = False
    auth.settings.registration_requires_approval = False
     
    appserver = "%(server_name)s:"\
        "%(server_port)s"%(request.env)

    appname = "%(application)s/default"%(request)

    appaddr = "%(appserver)s/%(appname)s"%locals()

    auth.messages.verify_email = \
        'Click on the link http://' + appaddr + \
        '/user/verify_email/%(key)s to verify '\
        'your email'

    # auth.settings.reset_password_requires_verification = True
    auth.messages.reset_password = \
        'Click on the link http://'+ appaddr+ \
        '/user/reset_password/%(key)s to '\
        'reset your password'
    # more options discussed in gluon/tools.py

    #--------------------------------------------------------
    # PeerTool application configuration
    #--------------------------------------------------------
    _ptcfg = local_import('config',reload=True)

    # The PeerToolConfig class defines various limits and
    # parameters for the PeerTool application.  The limits are mainly to prevent
    # abuse in public instances of the application.
    PTCFG = _ptcfg.PeerToolConfig()             # Global config object. 
                                                # Init with keyword args 
                                                # as needed to use different 
                                                # values. See modules/config.py
                                                # for details.



